package inv.loader.converters;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.beanutils.Converter;

public class DateConverter implements Converter {
	public final static SimpleDateFormat dateFormater	= new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.US);

	@SuppressWarnings("unchecked")
	public Object convert(Class arg0, Object arg1) {
		String str	= (String)arg1;
		try {
			return dateFormater.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static void main(String[] args) {
		Date date	= new Date();
		DateFormat df	= DateFormat.getDateInstance(DateFormat.FULL);
		DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
		
		System.out.println(date);
		System.out.println(df.format(date));
		System.out.println(df2.format(date));
	}

}
